import request from "@/utils/request";
import { ParamsType, ProjectCheckinCountQuery } from "@/api/checkin/types";

/**
 * 获取项目考勤日统计
 */
export function QueryPageProjectDay(data: ParamsType) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/page_project_day";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/page_project_day";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/page_project_day";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/page_project_day";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/page_project_day";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取人员考勤月统计
 */
export function getPersonCheckinMonth(data: ParamsType) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/page_person_month";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/page_person_month";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/page_person_month";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/page_person_month";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/page_person_month";
      break;
  }

  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 查询当前人员信息统计某个月考情详情
 */
export function getCheckInDetailPersonForm(memberId?: number, month?: string) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/getCheckInDetailPersonForm/" + memberId;
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/getCheckInDetailPersonForm/" + memberId;
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/getCheckInDetailPersonForm/" + memberId;
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/getCheckInDetailPersonForm/" + memberId;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/getCheckInDetailPersonForm/" + memberId;
      break;
  }
  return request({
    url: url,
    method: "get",
    params: { month: month },
  });
}

/**
 * 获取项目工程列表
 * @param data 请求参数
 * @returns Promise 包含项目工程列表的响应数据
 */
export function getProjectMagList(data: ParamsType) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/project/project_page";
      break;
    case "Corp":
      url = "/api/v1/corp/project/project_page";
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/project_page";
      break;
    case "Commander":
      url = "/api/v1/commander/project/project_page";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/project/project_page";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}
/**
 * 审核项目
 * @param {number} id - 项目ID
 * @param {object} data - 参数对象
 * @returns {Promise} - 请求结果的Promise对象
 */
export function auditProject(id, data) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/project/auditProject/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/project/auditProject/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/project/auditProject/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/project/auditProject/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/project/auditProject/" + id;
      break;
  }
  return request({
    url: url,
    method: "put",
    params: data,
  });
}

/**
 * 获取项目任务信息
 * @param id 项目id
 * @returns Promise 返回项目任务信息
 */
export function getProjectMagInfo(id: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      return request({
        url: `/api/v1/manager/project/${id}/projectform`,
        method: "get",
      });
    case "Corp":
      return request({
        url: `/api/v1/corp/project/${id}/projectform`,
        method: "get",
      });
    case "Constructor":
      return request({
        url: `/api
          /v1/constructor/project/${id}/projectform`,
        method: "get",
      });
    case "Commander":
      return request({
        url: `/api/v1/commander/project/${id}/projectform`,
        method: "get",
      });
    case "SysUser":
      return request({
        url: `/api/v1/sysuser/project/${id}/projectform`,
        method: "get",
      });
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取项目班组列表
 */
export function getProjectTeamList(data: ParamsType) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/page";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/page";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/page";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/page";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/projectgroup/page";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 根据班组ID 获取班组人员列表
 */
export function getProjectTeamMemberListByTeamId(id) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroupmember/getProjectGroupMemberByGroupId/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroupmember/getProjectGroupMemberByGroupId/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroupmember/getProjectGroupMemberByGroupId/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroupmember/getProjectGroupMemberByGroupId/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/projectgroupmember/getProjectGroupMemberByGroupId/" + id;
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取班组信息
 */
export function getProjectTeamInfo(id: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/projectgroup/" + id;
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取人员信息
 */
export function getPersonInfo(id: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/person/" + id + "/form";
      break;
    case "Corp":
      url = "/api/v1/corp/person/" + id + "/form";
      break;
    case "Constructor":
      url = "/api/v1/constructor/person/" + id + "/form";
      break;
    case "Commander":
      url = "/api/v1/commander/person/" + id + "/form";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/person/" + id + "/form";
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取考勤明细列表
 */
export function getAttendanceList(data: ParamsType) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/page";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/page";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/page";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/page";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/page";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 获取考勤
 */
export function getAttendanceInfo(id: string, month: string) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/" + id + "/" + month + "/form";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/" + id + "/" + month + "/form";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/" + id + "/" + month + "/form";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/" + id + "/" + month + "/form";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/" + id + "/" + month + "/form";
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 获取班组人员
 */
export function getGroupMember(data: ParamsType) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroupmember/page_projectGroupMembers";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroupmember/page_projectGroupMembers";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroupmember/page_projectGroupMembers";
      break;

    case "Commander":
      url = "/api/v1/commander/projectgroupmember/page_projectGroupMembers";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/projectgroupmember/page_projectGroupMembers";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: data,
  });
}

/**
 * 新增考勤明细列表
 */
export function addAttendance(data) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/create";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/create";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/create";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/create";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/create";
      break;
  }
  return request({
    url: url,
    method: "post",
    data: data,
  });
}

/**
 * 修改考勤明细列表
 */
export function editAttendance(id, data) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/" + id;
      break;
  }
  return request({
    url: url,
    method: "put",
    data: data,
  });
}

/**
 * 修改考勤明细列表
 */
export function deleteAttendance(id) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/" + id;
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/" + id;
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/" + id;
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/" + id;
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/" + id;
      break;
  }
  return request({
    url: url,
    method: "delete",
  });
}

/**
 * 获取所属公司下拉列表
 */
export function getProjectTeamPulldownList(projectId?: number) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/projectgroup/getProjectCorps";
      break;
    case "Corp":
      url = "/api/v1/corp/projectgroup/getProjectCorps";
      break;
    case "Constructor":
      url = "/api/v1/constructor/projectgroup/getProjectCorps";
      break;
    case "Commander":
      url = "/api/v1/commander/projectgroup/getProjectCorps";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/projectgroup/getProjectCorps/" + projectId;
      break;
  }
  return request({
    url: url,
    method: "get",
  });
}

/**
 * 项目考勤统计-数量统计
 */
export function getProjectCheckinCount(query: ProjectCheckinCountQuery) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/getProjectCheckinCount";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/getProjectCheckinCount";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/getProjectCheckinCount";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/getProjectCheckinCount";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/getProjectCheckinCount/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
  });
}

/**
 * 班组考勤分析
 */
export function getProjectGroupCheckinAnalysis(query: ProjectCheckinCountQuery) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/getProjectGroupCheckinAnalysis";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/getProjectGroupCheckinAnalysis";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/getProjectGroupCheckinAnalysis";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/getProjectGroupCheckinAnalysis";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/getProjectGroupCheckinAnalysis/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
  });
}

/**
 * 导出明细
 */
export function exportDetail(query: ProjectCheckinCountQuery) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/export";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/export";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/export";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/export";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/export/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
    responseType: "arraybuffer",
  });
}

/**
 * 导出明细
 */
export function exportDetailInfo(query: any) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/export_detail";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/export_detail";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/export_detail";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/export_detail";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/export_detail/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
    responseType: "arraybuffer",
  });
}

/**
 * 导出明细
 */
export function exportDetailMonth(query: any) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/export_month";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/export_month";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/export_month";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/export_month";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/export_month/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
    responseType: "arraybuffer",
  });
}

/**
 * 获取管理员考勤明细
 */
export function QueryPersonMonthDetailManager(query: any) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/page_person_month_detail_manager";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/page_person_month_detail_manager";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/page_person_month_detail_manager";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/page_person_month_detail_manager";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/page_person_month_detail_manager/";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
  });
}

/**
 * 获取工人考勤明细
 */
export function QueryPersonMonthDetailWorker(query: any) {
  let url;
  switch (localStorage.getItem("usertypeName")) {
    case "Manager":
      url = "/api/v1/manager/checkindetail/page_person_month_detail_worker";
      break;
    case "Corp":
      url = "/api/v1/corp/checkindetail/page_person_month_detail_worker";
      break;
    case "Constructor":
      url = "/api/v1/constructor/checkindetail/page_person_month_detail_worker";
      break;
    case "Commander":
      url = "/api/v1/commander/checkindetail/page_person_month_detail_worker";
      break;
    case "SysUser":
      url = "/api/v1/sysuser/checkindetail/page_person_month_detail_worker";
      break;
  }
  return request({
    url: url,
    method: "get",
    params: query,
  });
}
